
//  DFChannels.m
//  doubanFun
//
//  Created by bing on 16/3/24.
//  Copyright © 2016年 bing. All rights reserved.
//

#import "DFChannel.h"

@implementation DFChannel

- (instancetype)initWithDictionary:(NSDictionary *)dictionary {
    if (self = [super init]) {
        _name       = [dictionary stringForKey:@"name" or:@""];
        _channel_id = [dictionary stringForKey:@"channel_id" or:@""];
        _seq_id     = [[dictionary numberForKey:@"seq_id"] integerValue];;
        _abbr_en    = [dictionary stringForKey:@"abbr_en" or:@""];
        _name_en    = [dictionary stringForKey:@"name_en" or:@""];
    }
    return self;
}

+ (instancetype)initWithDictionary:(NSDictionary *)dictionary {
    return [[self alloc] initWithDictionary:dictionary];
}

- (NSString *)channel_id {
    if (!_channel_id || _channel_id.length < 1) {
        return @"0";
    }
    return _channel_id;
}

- (NSDictionary *)getDBParameter {
    NSMutableDictionary *parameter = [NSMutableDictionary dictionary];
    
    NSString *value = _channel_id;
    if (!value) {
        value = @"-1";
    }
    [parameter setValue:value forKey:@"channel_id"];
    
    value = _name;
    if (!value) {
        value = @"";
    }
    [parameter setValue:value forKey:@"name"];
    
    value = _abbr_en;
    if (!value) {
        value = @"";
    }
    [parameter setValue:value forKey:@"abbr_en"];
    
    value = _name_en;
    if (!value) {
        value = @"";
    }
    [parameter setValue:value forKey:@"name_en"];
    
    NSNumber *value1 = @(_seq_id);
    if (!value1) {
        value1 = @(-1);
    }
    [parameter setValue:value1 forKey:@"seq_id"];
    
    return parameter;
}

@end
